package com.css.fxfzfxqh.modules.downloadLegend.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzfxqh.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzfxqh.base.attachment.repository.AttachmentInfoRepository;
import com.css.fxfzfxqh.base.dict.repository.DictItemRepository;
import com.css.fxfzfxqh.base.dict.repository.entity.DictItemEntity;
import com.css.fxfzfxqh.base.response.RestResponse;
import com.css.fxfzfxqh.common.utils.UpdateUtil;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.entity.CalculationTasks;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.repository.CalculationTasksRepository;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.entity.PCC;
import com.css.fxfzfxqh.modules.buildings.probabilityEvaluation.publicOperate.service.PublicOperateService;
import com.css.fxfzfxqh.modules.downloadLegend.service.SupergraphService;
import com.css.fxfzfxqh.modules.downloadLegend.vo.LegendVO;
import com.css.fxfzfxqh.modules.reportmanagement.legend.*;
import com.css.fxfzfxqh.modules.reportmanagement.reportutil.DownloadsFile;
import com.css.fxfzfxqh.modules.reportmanagement.vo.LegendVo;
import com.css.fxfzfxqh.modules.reportmanagement.vo.RequestVO;
import com.css.fxfzfxqh.modules.reportmanagement.vo.ResponseVO;
import com.css.fxfzfxqh.modules.taskMaps.entity.TaskMaps;
import com.css.fxfzfxqh.modules.taskMaps.service.TaskMapsService;
import com.css.fxfzfxqh.modules.util.hypergraph.service.HypergraphService;
import com.css.fxfzfxqh.util.*;
import com.css.fxfzfxqh.zcpt.sys.service.SUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slw.common.helper.PropsHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.imageio.event.IIOReadProgressListener;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.*;


@Service
@Slf4j
public class SupergraphServiceImpl implements SupergraphService {
    @Resource
    RestTemplateUtil restTemplateUtil;

    @Value("${image.ctLocalDir}")
    private String ctLocalDir;
    @Value("${hypergraph.iServerHttp}")
    private String iServerHttp;
    @Resource
    private DownloadsFile downloadsFile;
    @Resource
    PublicOperateService publicOperateService;
    @Resource
    CalculationTasksRepository calculationTasksRepository;
    @Resource
    TaskMapsService taskMapsService;
    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    private HypergraphService hypergraphService;
    @Resource
    RestTemplate restTemplate;

    //超图web打印功能
    public RestResponse supergraph(RequestVO requestVO, String iServerHttpUrl, String token) throws Exception {
        RestResponse restResponse = null;
        String url = iServerHttpUrl + "/webprinting/rest/webprinting/v1/jobs.json?token=" + token;
        JSONObject requestJsonVo = (JSONObject) JSONObject.toJSON(requestVO);
        String json = JSONObject.toJSONString(requestJsonVo);
        log.info(json);
        Map map = JSONObject.parseObject(json, Map.class);
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendPostHttpRequest(url, map);
        String body = stringResponseEntity.getBody();
        List<ResponseVO> responseVO = JSON.parseArray(body, ResponseVO.class);
        String path = "";
        if (responseVO != null || responseVO.size() > 0) {
            path = responseVO.get(0).getPath() + "/" + "result";
            String savePath = ctLocalDir;
            path = path.replace("@", "%40");
            System.out.println("路径  " + path);

            String path2 = responseVO.get(0).getPath() + ".rjson";
            Map<String, Object> map2 = new HashMap<>();
            boolean flag = true;
            while (flag) {
                ResponseEntity<String> responseEntity = restTemplateUtil.sendHttpRequest(path2, map2);
                String body1 = responseEntity.getBody();
                String[] split1 = body1.split("status");
                if (split1[1].contains("ERROR")) {
                    log.error("超图服务打印失败");
//                    throw new CustomException("超图服务打印失败");
                }
                if (split1[1].contains("FINISHED")) {
                    flag = false;
                    continue;
                }
//                Thread.sleep(500);
            }
            //下载文件并获取文件ID
            // restResponse = downloadsFile.downloadByUrl(path, savePath,taskId,fileName,mapTemplate.getFlag());
        }
        File file = new File(ctLocalDir);
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()) {
                file1.delete();
            }
        }

        return restResponse;
    }

    @Override
    public RestResponse handle(LegendVO legendVo) {
        RestResponse restResponse = null;
        try {
            //任务id;
            String taskId = legendVo.getTaskId();

            MapTemplate mapTemplate = getMapTemplateData(legendVo);
            legendVo.setMapTemplate(mapTemplate);

            //获取任务范围矩形区域
            String extent = "";
            //获取任务范围中心点
            String center = "";
            if(legendVo.getDataType().equals("2") || legendVo.getDataType().equals("3")){//2生命线破坏等级分析图/3生命线功能失效分析图
                //获取任务范围矩形区域
                extent = getExtent2(taskId);
                //获取任务范围中心点
                center = getCenter2(extent);
            }else{
                //获取任务范围矩形区域
                extent = getExtent(taskId);
                //获取任务范围中心点
                center = getCenter(taskId);
            }
            if (PlatformObjectUtils.isEmpty(center) || PlatformObjectUtils.isEmpty(extent)) {
                log.error("center or extent is null");
                return null;
            }
            String[] split = extent.substring(4, extent.length() - 1).split(",");
            String[] s1 = split[0].split(" ");
            String[] s2 = split[1].split(" ");
            String leftX = s1[0];
            String leftY = s1[1];
            String rightX = s2[0];
            String rightY = s2[1];

            String format = legendVo.getFormat();
            String formatType = "横版";//测试横版
            if ("0".equals(format)) {//0横板
                formatType = "横版";//测试横版
            } else if ("1".equals(format)) {//1竖版
                formatType = "竖版";//测试竖版
            } else if ("2".equals(format)) {//1竖版
                formatType = "横版";//测试竖版
            } else if ("3".equals(format)) {//1竖版
                formatType = "竖版";//测试竖版
            }
            int level = getLevel(Double.parseDouble(leftX), Double.parseDouble(leftY), Double.parseDouble(rightX), Double.parseDouble(rightY), formatType);
            String[] s = center.substring(6, center.length() - 1).split(" ");
            String centerX = s[0];
            String centerY = s[1];
            Map<String, Double> hashMap = new HashMap<>();
            hashMap.put("leftX", Double.valueOf(leftX));
            hashMap.put("leftY", Double.valueOf(leftY));
            hashMap.put("rightX", Double.valueOf(rightX));
            hashMap.put("rightY", Double.valueOf(rightY));
            hashMap.put("centerX", Double.valueOf(centerX));
            hashMap.put("centerY", Double.valueOf(centerY));
            hashMap.put("level", (double) level);
            RequestVO requestVO = getRequestVO(legendVo, hashMap, taskId);

            restResponse = generateGraph(requestVO, taskId, mapTemplate);
            if (restResponse.getCode() == 200) {
                String attachId1 = legendVo.getAttachId();
                if (PlatformObjectUtils.isNotEmpty(attachId1)) {
                    taskMapsService.deleteById(attachId1);
                }
                String attachId = (String) restResponse.getData();
                TaskMaps entity = new TaskMaps();
                UpdateUtil.copyNullProperties(legendVo, entity);
                entity.setAttachId(attachId);
                taskMapsService.save(entity);
            }
        } catch (Exception e) {
            String errorMessage = "生成图件失败!";
            log.error(errorMessage, e);
            restResponse = RestResponse.fail(errorMessage);
        }
        return restResponse;
    }

    private MapTemplate getMapTemplateData(LegendVO legendVo) {
        MapTemplate mapTemplate = new MapTemplate();
        String flag = null;
        String dictCode = null;
        String serverIpPort = iServerHttp + "/iserver/services/";
        String serverUrl = null;
        //0评估/1区划/2生命线破坏等级分析图/3生命线功能失效分析图
        String dataType = legendVo.getDataType();
        if ("0".equals(dataType)) {
            //评估方式 0为确定评估1为概率评估
            String assessType = legendVo.getAssessType();
            //评估对象0为结构破坏,1为人员伤亡,2为经济损失
            String assessObj = legendVo.getAssessObj();
            if ("0".equals(assessType)) {
                if ("0".equals(assessObj)) {
                    dictCode = "pg_ed_jgph";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_resist_earthquakes_calculation_ed@fxfzfxqh";
                } else if ("1".equals(assessObj)) {
                    //人员伤亡时rysw1：重伤rysw2：死亡
                    String casualties = legendVo.getCasualties();
                    //人员伤亡时sjd1：白天sjd2：夜晚
                    String times = legendVo.getTimes();
                    if ("rysw1".equals(casualties)) {
                        if ("sjd1".equals(times)) {
                            dictCode = "pg_ed_ryss0";
                            serverUrl = "map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_day_injure@fxfzfxqh";
                        } else {
                            dictCode = "pg_ed_ryss1";
                            serverUrl = "map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_night_injure@fxfzfxqh";
                        }
                    } else if ("rysw2".equals(casualties)) {
                        if ("sjd1".equals(times)) {
                            dictCode = "pg_ed_rysw0";
                            serverUrl = "map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_day_death@fxfzfxqh";
                        } else {
                            dictCode = "pg_ed_rysw1";
                            serverUrl = "map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_night_death@fxfzfxqh";
                        }
                    }
                } else if ("2".equals(assessObj)) {
                    dictCode = "pg_ed_jjss";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_economic_loss_calculation_ed@fxfzfxqh";
                }
            } else if ("1".equals(assessType)) {
                if ("0".equals(assessObj)) {
                    dictCode = "pg_pd_jgph";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_resist_earthquakes_calculation_pd@fxfzfxqh";
                } else if ("1".equals(assessObj) ) {
                    dictCode = "pg_pd_rysw";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_pd@fxfzfxqh";
                } else if ("2".equals(assessObj)) {
                    dictCode = "pg_pd_jjss";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_economic_loss_calculation_pd@fxfzfxqh";
                }
            }
        } else if ("1".equals(dataType)) {
            //评估方式 0为确定评估1为概率评估
            String assessType = legendVo.getAssessType();
            //区划：0时单指标风险区划；1时综合指标风险区划
            String qhType = legendVo.getQhType();
            if ("0".equals(qhType)) {
                if ("0".equals(assessType)) {
                    dictCode = "qh_ed_dzb";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result@fxfzfxqh";
                } else if ("1".equals(assessType)) {
                    dictCode = "qh_pd_dzb";
                    serverUrl = "map-fxfzfxqh/rest/maps/fxqh_assess_pd_qh_result@fxfzfxqh";
                }
            } else if ("1".equals(qhType)) {
                dictCode = "qh_zhzb";
                serverUrl = "map-fxfzfxqh/rest/maps/fxqh_composite_assess@fxfzfxqh";
            }
        } else if ("2".equals(dataType)) {//生命线破坏等级分析图
            // //生命线时1地下管网，2水厂水池，3燃气储气罐 4 桥梁 5道路 6变电站 8电缆线路 9通信室内设备 11 水厂泵房 12 重要发电厂房 13 通信基站 14 燃气门站  15 供气
            // String assessObj=legendVo.getAssessObj();
            //地震输入方式0为设定烈度,1为地震影响场
            String seismicInputMode = legendVo.getSeismicInputMode();
            //烈度时（ld1，ld2，ld3，ld4，ld5）；
            String condition = legendVo.getCondition();
            if ("0".equals(seismicInputMode)) {
                switch (condition) {
                    case "ld1":
                        dictCode = "smx_ld1";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6@fxfzfxqh";//点数据图层
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_6@fxfzfxqh";//线数据图层
                        break;
                    case "ld2":
                        dictCode = "smx_ld2";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_7@fxfzfxqh";
                        break;
                    case "ld3":
                        dictCode = "smx_ld3";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_8@fxfzfxqh";
                        break;
                    case "ld4":
                        dictCode = "smx_ld4";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_9@fxfzfxqh";
                        break;
                    case "ld5":
                        dictCode = "smx_ld5";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_10@fxfzfxqh";
                        break;
                }
            }else if ("1".equals(seismicInputMode)){
                dictCode = "smx_influence";
                serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence@fxfzfxqh";
                serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_influence@fxfzfxqh";
            }
        } else if ("3".equals(dataType)) {//生命线功能失效分析图
            // //生命线时1地下管网，2水厂水池，3燃气储气罐 4 桥梁 5道路 6变电站 8电缆线路 9通信室内设备 11 水厂泵房 12 重要发电厂房 13 通信基站 14 燃气门站  15 供气
            // String assessObj=legendVo.getAssessObj();
            //地震输入方式0为设定烈度,1为地震影响场
            String seismicInputMode = legendVo.getSeismicInputMode();
            //烈度时（ld1，ld2，ld3，ld4，ld5）；
            String condition = legendVo.getCondition();
            if ("0".equals(seismicInputMode)) {
                switch (condition) {
                    case "ld1":
                        dictCode = "smx_failureLevel_ld1";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6_failureLevel@fxfzfxqh";//点数据图层
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6_line_failureLevel@fxfzfxqh";//线数据图层
                        break;
                    case "ld2":
                        dictCode = "smx_failureLevel_ld2";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7_failureLevel@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7_line_failureLevel@fxfzfxqh";
                        break;
                    case "ld3":
                        dictCode = "smx_failureLevel_ld3";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8_failureLevel@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8_line_failureLevel@fxfzfxqh";
                        break;
                    case "ld4":
                        dictCode = "smx_failureLevel_ld4";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9_failureLevel@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9_line_failureLevel@fxfzfxqh";
                        break;
                    case "ld5":
                        dictCode = "smx_failureLevel_ld5";
                        serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10_failureLevel@fxfzfxqh";
                        serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10_line_failureLevel@fxfzfxqh";
                        break;
                }
            }else if ("1".equals(seismicInputMode)){
                dictCode = "smx_failureLevel_influence";
                serverUrl = "map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence_failureLevel@fxfzfxqh";
                serverUrl += ",map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence_line_failureLevel@fxfzfxqh";
            }
        }
        mapTemplate.setDictCode(dictCode);
        mapTemplate.setServerIpPort(serverIpPort);
        mapTemplate.setServerUrl(serverUrl);
        if (PlatformObjectUtils.isEmpty(flag)) {
            flag = dictCode;
        }
        mapTemplate.setFlag(flag);
        return mapTemplate;
    }

    //获取范围矩形区域
    public String getExtent(String taskId) {
        String extent = null;
        List<PCC> pccList = getPCCDataQueryParam(taskId);
        try {
            String geom = publicOperateService.getUnionGeomByCode(pccList);
            log.info("geom>>>>", geom);
//            String sql ="select ST_extent(?) as geom";
            String sql = "select ST_extent ( st_geometryfromtext(?,4490) ) ";
            extent = jdbcTemplate.queryForObject(sql, String.class, geom);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return extent;
    }

    //获取范围中心点
    public String getCenter(String taskId) {
        String center = null;
        List<PCC> pccList = getPCCDataQueryParam(taskId);
        try {
            String geom = publicOperateService.getUnionGeomByCode(pccList);
            String sql = "select ST_AsText(ST_Centroid(ST_extent(st_geometryfromtext(?,4490) )))  as geom  ";
            center = jdbcTemplate.queryForObject(sql, String.class, geom);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return center;
    }

    //获取范围矩形区域
    public String getExtent1(String geomText) {
        String sql = "select ST_extent(st_geomfromtext('" + geomText + "',4490))";
        return jdbcTemplate.queryForObject(sql, String.class);
    }

    //获取范围中心点
    public String getCenter1(String geomText) {
        String sql = "select ST_AsText(ST_Centroid(ST_extent(st_geomfromtext('" + geomText + "',4490))))";
        return jdbcTemplate.queryForObject(sql, String.class);
    }

    //获取范围矩形区域--生命线评估结果
    public String getExtent2(String taskId) {
        String extent = null;
        try {
            //点数据范围
            String sql = "select st_extent(geom) FROM fxqh_smx_evaluation_results WHERE task_id = ? and del_flag='0'";
            String extent0 = jdbcTemplate.queryForObject(sql, String.class,taskId);
            String[] split = extent0.substring(4, extent0.length() - 1).split(",");
            String[] s1 = split[0].split(" ");
            String[] s2 = split[1].split(" ");
            Double leftX = Double.valueOf(s1[0]);
            Double leftY = Double.valueOf(s1[1]);
            Double rightX = Double.valueOf(s2[0]);
            Double rightY = Double.valueOf(s2[1]);
            //线数据范围
            String sql1 = "select st_extent(geom) FROM fxqh_smx_evaluation_results_line WHERE task_id = ? and del_flag='0'";
            String extent1 = jdbcTemplate.queryForObject(sql1, String.class,taskId);
            String[] split1 = extent1.substring(4, extent1.length() - 1).split(",");
            String[] s11 = split1[0].split(" ");
            String[] s21 = split1[1].split(" ");
            Double leftX1 = Double.valueOf(s11[0]);
            Double leftY1 = Double.valueOf(s11[1]);
            Double rightX1 = Double.valueOf(s21[0]);
            Double rightY1 = Double.valueOf(s21[1]);
            if(leftX>leftX1){
                leftX = leftX1;
            }
            if(leftY>leftY1){
                leftY = leftY1;
            }
            if(rightX<rightX1){
                rightX = rightX1;
            }
            if(rightY<rightY1){
                rightY = rightY1;
            }
            extent = "BOX("+leftX+" "+leftY+","+rightX+" "+rightY+")";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return extent;
    }

    //获取范围中心点--生命线评估结果
    public String getCenter2(String extent) {
        String center = null;
        try {
            String[] split = extent.substring(4, extent.length() - 1).split(",");
            String[] s1 = split[0].split(" ");
            String[] s2 = split[1].split(" ");
            Double leftX = Double.valueOf(s1[0]);
            Double leftY = Double.valueOf(s1[1]);
            Double rightX = Double.valueOf(s2[0]);
            Double rightY = Double.valueOf(s2[1]);
            String geomText = "POLYGON(("+leftX+" "+leftY+","+leftX+" "+rightY+","+rightX+" "+rightY+","+rightX+" "+leftY+","+leftX+" "+leftY+"))";
            String sql = "select ST_AsText(ST_Centroid(ST_extent(st_geomfromtext('" + geomText + "',4490))))";
            return jdbcTemplate.queryForObject(sql, String.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return center;
    }

    private List<PCC> getPCCDataQueryParam(String taskId) {
        StringBuilder sb = new StringBuilder();
        sb.append("select t2.pp_name ,t2.city_name   ,t2.NAME     ");
        sb.append("from fxqh_calculation_tasks t1                                           ");
        sb.append("left join fxqh_assess_toponym t2  on t1.id=t2.assess_id                  ");
        sb.append("where t1.id=?                       ");
        List<PCC> pccList = jdbcTemplate.query(sb.toString(), new BeanPropertyRowMapper<>(PCC.class), taskId);
        return pccList;
    }

    //根据经纬度范围获取level值
    public int getLevel(double leftBottom_X, double leftBottom_Y, double rightTop_X, double rightTop_Y, String formatType) {
        int level = 4;//默认级别4
        int width, height;
        if (formatType.equals("横版")) {
            width = 1510;
            height = 1020;
        } else if (formatType.equals("竖版")) {//竖版
            width = 1150;
            height = 1230;
        } else {//横版带简介
            width = 1160;
            height = 1010;
        }
        //根据区域范围计算zoom级别，width、height是以像素为单位的地图布局大小
        level = getBoundsZoomLevel(leftBottom_X, leftBottom_Y, rightTop_X, rightTop_Y, width, height);

        return level;
    }

    final static int GLOBE_WIDTH = 256;
    final static int ZOOM_MAX = 18;

    //根据区域范围计算zoom级别，width、height是以像素为单位的地图布局大小
    public static int getBoundsZoomLevel(double leftBottom_X, double leftBottom_Y, double rightTop_X, double rightTop_Y,
                                         int width, int height) {
        double latFraction = (latRad(rightTop_Y) - latRad(leftBottom_Y)) / Math.PI;
        double lngDiff = rightTop_X - leftBottom_X;
        double lngFraction = ((lngDiff < 0) ? (lngDiff + 360) : lngDiff) / 360;
        double latZoom = zoom(height, GLOBE_WIDTH, latFraction);
        double lngZoom = zoom(width, GLOBE_WIDTH, lngFraction);
        double zoom = Math.min(Math.min(latZoom, lngZoom), ZOOM_MAX);
        return (int) (zoom);
    }

    private static double latRad(double lat) {
        double sin = Math.sin(lat * Math.PI / 180);
        double radX2 = Math.log((1 + sin) / (1 - sin)) / 2;
        return Math.max(Math.min(radX2, Math.PI), -Math.PI) / 2;
    }

    private static double zoom(double mapPx, double worldPx, double fraction) {
        final double LN2 = .693147180559945309417;
        return (Math.log(mapPx / worldPx / fraction) / LN2);
    }

    //设置打印出图请求体
    private RequestVO getRequestVO(LegendVO legendVo, Map<String, Double> hashMap, String taskId) {
        RequestVO requestVO = new RequestVO();
        LayoutOptions layoutOptions = new LayoutOptions();
        String templateName = "Administrative_Active_Fault-hf1012";
        String format = legendVo.getFormat();//版式  0横板  1竖版  2无 3横版带简介
        if (format.equals("0")) {//0横板
            templateName = "Administrative_Active_Fault-hf1012";//测试横版
        } else if (format.equals("1")) {//1竖版
            templateName = "Administrative_Active_Fault-v1012";//测试竖版
        } else if (format.equals("2")) {//2无
            templateName = "Administrative_Active_Fault-hf1012";//测试横版
        } else if (format.equals("3")) {//3横版带简介
            templateName = "Administrative_Active_Fault-h1012";//测试横版带简介
        }
        layoutOptions.setTemplateName(templateName);//test
        String title = legendVo.getTitle();
        if (PlatformObjectUtils.isEmpty(title)) {
            title = "标题";
        }
        layoutOptions.setTitle(title);//标题
        layoutOptions.setAuthor("制图单位：" + legendVo.getUnit());//制图单位
        String date = DateUtil.format(new Date(), "yyyy年MM月dd日");
        layoutOptions.setTime("制图时间:" + date);//制图时间
        // if("RealAnalyse_Kangzhen".equals(mapTemplate.getDictCode())){//基于遥感影像的XX震中影响场范围内房屋抗震能力初判图
        //     //用URLEncode编码，防止如%符号不能打印
        //     String summaryText = setStringEncoder(legendVo.getSummaryText());
        //     layoutOptions.setSummaryText(summaryText);
        // }
        ScaleBarOptions scaleBarOptions = new ScaleBarOptions("", "BAR", 5, "METER");
        layoutOptions.setScaleBarOptions(scaleBarOptions);
//        NorthArrowOptions northArrowOptions = new NorthArrowOptions("file://NorthArrow.svg");
        NorthArrowOptions northArrowOptions = new NorthArrowOptions("file://ARROW_RIGHT_FILL_WITH_COLOR.svg");
        layoutOptions.setNorthArrowOptions(northArrowOptions);
//        MapGridOptions mapGridOptions = new MapGridOptions();//经纬度网格边框
//        mapGridOptions.setOriginX(-180);
//        mapGridOptions.setOriginY(-90);
//        mapGridOptions.setCellWidth(10);
//        mapGridOptions.setCellHeight(10);
//        mapGridOptions.setMarkType("DMS");
        //获取经纬网参数
        MapGridOptions mapGridOptions = getMapGridOptions(hashMap.get("leftX"), hashMap.get("leftY"), hashMap.get("rightX"), hashMap.get("rightY"));
        layoutOptions.setMapGridOptions(mapGridOptions);
        LegendOption legendOption = new LegendOption();
        legendOption.setTitle("图 例");
        //根据dictCode、任务ID获取临时图层URL的Map
        Map<String, String> tempLayerUrlMap = getTempLayerUrlMapByDictCode1(legendVo, taskId);
        List<Layerr> layerrs = getLayerrs(legendVo, tempLayerUrlMap);
        legendOption.setLayers(layerrs);
        layoutOptions.setLegendOptions(legendOption);
        requestVO.setLayoutOptions(layoutOptions);
        ExportOptions exportOptions = new ExportOptions("png", 120.0);
        requestVO.setExportOptions(exportOptions);
        Content content = new Content();
        content.setType("WEBMAP");
        com.css.fxfzfxqh.modules.reportmanagement.legend.Value value = new com.css.fxfzfxqh.modules.reportmanagement.legend.Value();
        LeftAndright leftBottom = new LeftAndright(hashMap.get("leftX"), hashMap.get("leftY"));
        LeftAndright rightTop = new LeftAndright(hashMap.get("rightX"), hashMap.get("rightY"));
        Extent extent = new Extent(leftBottom, rightTop);
        value.setExtent(extent);
        value.setMaxScale("1:2130.3378410848");
        value.setLevel(hashMap.get("level"));
        // if (format.equals("3")) {//3横版带简介
        //     int level = getLevel(hashMap.get("leftX"), hashMap.get("leftY"), hashMap.get("rightX"), hashMap.get("rightY"), "横版带简介");
        //     value.setLevel((double) level);
        // }
//        value.setLevel(11.0);
        LeftAndright center = new LeftAndright(hashMap.get("centerX"), hashMap.get("centerY"));
        value.setCenter(center);
        List<Layer> layers = getLayers(legendVo, tempLayerUrlMap);
        value.setLayers(layers);
        value.setDescription("");
        value.setProjection("EPSG:4490");
        value.setMinScale("1:591658710.909131");
        value.setTitle("China");
        value.setVersion("2.3.0");
        content.setValue(value);
        requestVO.setContent(content);
        return requestVO;
    }

    //用URLEncode编码，防止如%符号不能打印
    public String setStringEncoder(String string) {
        String stringEncoder = string;
        try {
            stringEncoder = URLEncoder.encode(string, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return stringEncoder;
    }

    //获取经纬网参数
    @Override
    public MapGridOptions getMapGridOptions(double leftBottom_X,double leftBottom_Y,double rightTop_X,double rightTop_Y) {
        double minLon = leftBottom_X;
        double minLat = leftBottom_Y;
        double maxLon = rightTop_X;
        double maxLat = rightTop_Y;
        //获取经度差值
        double diffLon = maxLon - minLon;
        double tempLon = diffLon / 4;
        if(tempLon>1){
            tempLon = Math.round(tempLon);
        }else if(tempLon>0.5){
            tempLon = 0.5;//30分
        }else if(tempLon>0.25){
            tempLon = 0.25;//15分
        }else if(tempLon>0.125){
            tempLon = 0.125;//7分30秒
        }else if(tempLon>0.0625){
            tempLon = 0.0625;//3分45秒
        }else if(tempLon>0.05){
            tempLon = 0.05;//3分
        }else if(tempLon>0.025){
            tempLon = 0.025;//1分30秒
        }else if(tempLon>0.0125){
            tempLon = 0.0125;//45秒
        }else{
            tempLon = 0.0025;//9秒
        }
        //获取纬度差值
        double diffLat = maxLat - minLat;
        double tempLat = diffLat / 3;
        if(tempLat>1){
            tempLat = Math.round(tempLat);
        }else if(tempLat>0.5){
            tempLat = 0.5;//30分
        }else if(tempLat>0.25){
            tempLat = 0.25;//15分
        }else if(tempLat>0.125){
            tempLat = 0.125;//7分30秒
        }else if(tempLat>0.0625){
            tempLat = 0.0625;//3分45秒
        }else if(tempLat>0.05){
            tempLat = 0.05;//3分
        }else if(tempLat>0.025){
            tempLat = 0.025;//1分30秒
        }else if(tempLat>0.0125){
            tempLat = 0.0125;//45秒
        }else{
            tempLat = 0.0025;//9秒
        }
        MapGridOptions mapGridOptions = new MapGridOptions();//经纬度网格边框
        mapGridOptions.setOriginX(-180);
        mapGridOptions.setOriginY(-90);
        mapGridOptions.setCellWidth(tempLon);
        mapGridOptions.setCellHeight(tempLat);
        mapGridOptions.setMarkType("DMS");

        return mapGridOptions;
    }

    public Map<String, String> getTempLayerUrlMapByDictCode1(LegendVO legendVo, String taskId) {
        Map<String, String> tempLayerUrlMap = new HashMap<>();
        MapTemplate mapTemplate = legendVo.getMapTemplate();
        String dictCode = mapTemplate.getDictCode();
        CalculationTasks calculationTasks = null;
        //0评估/1区划/2生命线破坏等级分析图/3生命线功能失效分析图
        String dataType = legendVo.getDataType();
        if ("0".equals(dataType) || "1".equals(dataType)) {
            calculationTasks = calculationTasksRepository.findById(taskId);
        }
        if ("0".equals(dataType)) {
            //评估对象0为结构破坏,1为人员伤亡,2为经济损失
            String assessObj = legendVo.getAssessObj();
            //评估方式 0为确定评估1为概率评估
            String assessType = legendVo.getAssessType();
            //地震输入方式0为设定烈度1为四个概率,2为地震影响场,  3为发生概率危险性,4为超越概率危险性
            String seismicInputMode = legendVo.getSeismicInputMode();
            if ("0".equals(assessType)) {
                //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）；4个概率水准时（sgglsz1、sgglsz2、sgglsz3、sgglsz4）//概率评估：T年
                String condition = legendVo.getCondition();
                if ("0".equals(assessObj)) {
                    //结构破坏：破坏程度（pgcd1）
                    String destory = legendVo.getDestroy();
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                    if ("2".equals(seismicInputMode)) {
                        sb.append(" and version='").append(calculationTasks.getInfluenceFieldVersion()).append("'");
                        condition = "dzyxc";
                    } else {
                        sb.append(" and condition='").append(condition).append("'");
                    }
                    sb.append(" and damage_degree='").append(destory).append("'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);
                    mapTemplate.setFlag(dictCode + "_" + condition + "_" + destory);
                } else if ("1".equals(assessObj)) {
                    //人员伤亡时1：重伤2：死亡
                    String casualties = legendVo.getCasualties();
                    //人员伤亡时0：白天1：夜晚
                    String times = legendVo.getTimes();
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                    if ("0".equals(seismicInputMode)) {
                        //烈度 condition就是烈度 ld1-ld5  casualties
                        if ("ld1".equals(condition)) {
                            sb.append(" and intensity='Ⅵ'");
                        } else if ("ld2".equals(condition)) {
                            sb.append(" and intensity='Ⅶ'");
                        } else if ("ld3".equals(condition)) {
                            sb.append(" and intensity='Ⅷ'");
                        } else if ("ld4".equals(condition)) {
                            sb.append(" and intensity='Ⅸ'");
                        } else if ("ld5".equals(condition)) {
                            sb.append(" and intensity='Ⅹ'");
                        }
                    } else if ("1".equals(seismicInputMode)) {
                        //四个概率水准  condition就是四个概率水准版本
                        sb.append(" and condition='").append(condition).append("'");
                    } else if ("2".equals(seismicInputMode)) {
                        //地震影响场 condition就是地震影响场版本
                        sb.append(" and version='").append(calculationTasks.getInfluenceFieldVersion()).append("'");
                        condition = "dzyxc";
                    }
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);

                    mapTemplate.setFlag(dictCode + "_" + condition);
                } else if ("2".equals(assessObj)) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                    if ("2".equals(seismicInputMode)) {
                        sb.append(" and condition='").append(calculationTasks.getInfluenceFieldVersion()).append("'");
                        condition = "dzyxc";
                    } else {
                        sb.append(" and condition='").append(condition).append("'");
                    }
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);

                    mapTemplate.setFlag(dictCode + "_" + condition);
                }
            } else if ("1".equals(assessType)) {
                // 概率评估：T年
                //String year=legendVo.getYear();
                if ("0".equals(assessObj)) {
                    //结构破坏：破坏程度
                    String destroy = legendVo.getDestroy();
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                    //sb.append(" and years='").append(year).append("'");
                    sb.append(" and damage_degree='").append(destroy).append("'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);

                    //mapTemplate.setFlag(dictCode + "_" + year + "_" + destroy);
                    mapTemplate.setFlag(dictCode + "_" + destroy);
                } else if ("1".equals(assessObj)) {
                    //人员伤亡时1：重伤2：死亡
                    String casualties = legendVo.getCasualties();
                    //人员伤亡时0：白天1：夜晚
                    String times = legendVo.getTimes();
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                    sb.append(" and casualties='").append(casualties).append("'");
                    sb.append(" and time='").append(times).append("'");
                    //sb.append(" and years='").append(year).append("'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);
                    mapTemplate.setFlag(dictCode );
//                    mapTemplate.setFlag(dictCode + "_" + year);
                } else if ("2".equals(assessObj)) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(" assess_id='").append(taskId).append("'");
                   // sb.append(" and years='").append(year).append("'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);
                    mapTemplate.setFlag(dictCode );
                   // mapTemplate.setFlag(dictCode + "_" + year);
                }
            }
        } else if ("1".equals(dataType)) {
            //区划：0时单指标风险区划；1时综合指标风险区划
            String qhType = legendVo.getQhType();
            //评估对象0为结构破坏,1为人员伤亡,2为经济损失
            String assessObj = legendVo.getAssessObj();
            //评估方式 0为确定评估1为概率评估
            String assessType = legendVo.getAssessType();
            //地震输入方式0为设定烈度1为四个概率,2为地震影响场,  3为发生概率危险性,4为超越概率危险性
            String seismicInputMode = legendVo.getSeismicInputMode();
            if ("0".equals(qhType)) {
                if ("0".equals(assessType)) {
                    //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）；4个概率水准时（sgglsz1、sgglsz2、sgglsz3、sgglsz4）
                    String condition = legendVo.getCondition();
                    StringBuilder sb = new StringBuilder();
                    sb.append("task_id='").append(taskId).append("'");
                    if ("2".equals(seismicInputMode)) {
                        sb.append(" and condition='").append(calculationTasks.getInfluenceFieldVersion()).append("'");
                        condition = "dzyxc";
                    } else {
                        sb.append(" and condition='").append(condition).append("'");
                    }
                    sb.append(" and estimate_obj='").append(assessObj).append("'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);

                    mapTemplate.setFlag(dictCode + "_" + assessObj + "_" + condition);
                } else if ("1".equals(assessType)) {
                    // 概率评估：T年
                    //String year = legendVo.getYear();
                    StringBuffer sb = new StringBuffer();
                    sb.append("task_id='" + taskId + "'");
//                    sb.append(" and condition='" + year + "'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);
                    mapTemplate.setFlag(dictCode + "_" + assessObj );
                    //mapTemplate.setFlag(dictCode + "_" + assessObj + "_" + year);
                }
            } else if ("1".equals(qhType)) {
                if ("0".equals(assessType)) {
                    //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）；4个概率水准时（sgglsz1、sgglsz2、sgglsz3、sgglsz4）
                    String condition = legendVo.getCondition();
                    StringBuilder sb = new StringBuilder();
                    sb.append("task_id='").append(taskId).append("'");
                    if ("2".equals(seismicInputMode)) {
                        sb.append(" and type='").append(calculationTasks.getInfluenceFieldVersion()).append("'");
                        condition = "dzyxc";
                    } else {
                        sb.append(" and type='").append(condition).append("'");
                    }
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);

                    mapTemplate.setFlag(dictCode + "_" + condition);
                } else if ("1".equals(assessType)) {
                    // 概率评估：T年
                    //String year = legendVo.getYear();
                    StringBuffer sb = new StringBuffer();
                    sb.append("task_id='" + taskId + "'");
                    //sb.append(" and type='" + year + "'");
                    String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
                    tempLayerUrlMap.put(dictCode, tempLayerUrl);
                    mapTemplate.setFlag(dictCode );
                   // mapTemplate.setFlag(dictCode + "_" + year);
                }
            }
        } else if ("2".equals(dataType) || "3".equals(dataType)) {//生命线破坏等级分析图、功能失效分析图
            //0供水系统，1供气系统，2供电系统，3交通系统，4通信系统，
            String assessObj = legendVo.getAssessObj();
            //地震输入方式0为设定烈度,1为地震影响场
//            String seismicInputMode = legendVo.getSeismicInputMode();
            //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）
//            String condition = legendVo.getCondition();
            if ("0".equals(assessObj)) {
                //1地下管网，2水厂水池，11 水厂泵房
//                getParam(taskId, "1", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "2", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "11", mapTemplate, tempLayerUrlMap);
                String sqlText = " task_id='" + taskId + "' and del_flag='0' and (type=1 or type=2 or type=11)";
                getParamTempLayer(sqlText,mapTemplate, tempLayerUrlMap);
            } else if ("1".equals(assessObj)) {
                //3燃气储气罐14 燃气门站15 供气
//                getParam(taskId, "3", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "14", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "15", mapTemplate, tempLayerUrlMap);
                String sqlText = " task_id='" + taskId + "' and del_flag='0' and (type=3 or type=14 or type=15)";
                getParamTempLayer(sqlText,mapTemplate, tempLayerUrlMap);
            } else if ("2".equals(assessObj)) {
                //6变电站 8电缆线路12 重要发电厂房
//                getParam(taskId, "6", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "8", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "12", mapTemplate, tempLayerUrlMap);
                String sqlText = " task_id='" + taskId + "' and del_flag='0' and (type=6 or type=8 or type=12)";
                getParamTempLayer(sqlText,mapTemplate, tempLayerUrlMap);
            } else if ("3".equals(assessObj)) {
                //4 桥梁 5道路
//                getParam(taskId, "4", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "5", mapTemplate, tempLayerUrlMap);
                String sqlText = " task_id='" + taskId + "' and del_flag='0' and (type=4 or type=5)";
                getParamTempLayer(sqlText,mapTemplate, tempLayerUrlMap);
            } else if ("4".equals(assessObj)) {
                //9通信室内设备   13 通信基站
//                getParam(taskId, "9", mapTemplate, tempLayerUrlMap);
//                getParam(taskId, "13", mapTemplate, tempLayerUrlMap);
                String sqlText = " task_id='" + taskId + "' and del_flag='0' and (type=9 or type=13)";
                getParamTempLayer(sqlText,mapTemplate, tempLayerUrlMap);
            }
        }
        return tempLayerUrlMap;
    }

    /*//生命线获取临时图层
    private void getParam(String taskId, String type, MapTemplate mapTemplate, Map<String, String> tempLayerUrlMap) {
        StringBuffer sb = new StringBuffer();
        sb.append(" task_id='" + taskId + "'");
        sb.append(" and type=" + type);
        sb.append(" and del_flag='0'");
//        String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + mapTemplate.getServerUrl(), sb.toString(), true);
//        tempLayerUrlMap.put(mapTemplate.getDictCode() + "_" + type, tempLayerUrl);
        String tempServerUrl = mapTemplate.getServerUrl();
        String[] tempServerUrlArr = tempServerUrl.split(",");
        //点数据临时图层
        String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + tempServerUrlArr[0], sb.toString(), true);
        tempLayerUrlMap.put(mapTemplate.getDictCode() + "_" + type, tempLayerUrl);
        //线数据临时图层
        String tempLineLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + tempServerUrlArr[1], sb.toString(), true);
        tempLayerUrlMap.put(mapTemplate.getDictCode() + "_line" + type, tempLineLayerUrl);
    }*/

    //生命线获取临时图层
    private void getParamTempLayer(String sqlText, MapTemplate mapTemplate, Map<String, String> tempLayerUrlMap) {
        String tempServerUrl = mapTemplate.getServerUrl();
        String[] tempServerUrlArr = tempServerUrl.split(",");
        //点数据临时图层
        String tempLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + tempServerUrlArr[0], sqlText, true);
        tempLayerUrlMap.put(mapTemplate.getDictCode(), tempLayerUrl);
        //线数据临时图层
        String tempLineLayerUrl = getSqlTempLayer(mapTemplate.getServerIpPort() + tempServerUrlArr[1], sqlText, true);
        tempLayerUrlMap.put(mapTemplate.getDictCode() + "_line", tempLineLayerUrl);
    }

    private List<Layerr> getLayerrs(LegendVO legendVo, Map<String, String> tempLayerUrlMap) {
        MapTemplate mapTemplate = legendVo.getMapTemplate();
        List<Layerr> layerrs = new ArrayList<>();
        String serverUrl1 = mapTemplate.getServerUrl();
        String serverUrl = mapTemplate.getServerIpPort() + serverUrl1;
        if (tempLayerUrlMap != null && !tempLayerUrlMap.isEmpty()) {
            //0评估/1区划/2生命线破坏等级分析图/3生命线功能失效分析图
            String dataType = legendVo.getDataType();
            if ("0".equals(dataType) || "1".equals(dataType)) {
                serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode());
                Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                layerrs.add(layerr1);
            } else if ("2".equals(dataType) || "3".equals(dataType)) {//生命线破坏等级分析图、功能失效分析图
                //0供水系统，1供气系统，2供电系统，3交通系统，4通信系统，
                /*String assessObj = legendVo.getAssessObj();
                //地震输入方式0为设定烈度,1为地震影响场
//                String seismicInputMode = legendVo.getSeismicInputMode();
                //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）
//                String condition = legendVo.getCondition();
                if ("0".equals(assessObj)) {
                    //1地下管网，2水厂水池，11 水厂泵房
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_1");
                    Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerr1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_2");
//                    Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_11");
//                    Layerr layerr3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr3);
                    //线数据
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line1");
                    Layerr layerrline1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerrline1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line2");
//                    Layerr layerrline2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line11");
//                    Layerr layerrline3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline3);
                } else if ("1".equals(assessObj)) {
                    //3燃气储气罐14 燃气门站15 供气
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_3");
                    Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerr1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_14");
//                    Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_15");
//                    Layerr layerr3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr3);
                    //线数据
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line3");
                    Layerr layerrline1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerrline1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line14");
//                    Layerr layerrline2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line15");
//                    Layerr layerrline3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline3);
                } else if ("2".equals(assessObj)) {
                    //6变电站 8电缆线路12 重要发电厂房
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_6");
                    Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerr1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_8");
//                    Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_12");
//                    Layerr layerr3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr3);
                    //线数据
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line6");
                    Layerr layerrline1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerrline1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line8");
//                    Layerr layerrline2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline2);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line12");
//                    Layerr layerrline3 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline3);
                } else if ("3".equals(assessObj)) {
                    //4 桥梁 5道路
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_4");
                    Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerr1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_5");
//                    Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr2);
                    //线数据
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line4");
                    Layerr layerrline1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerrline1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line5");
//                    Layerr layerrline2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline2);
                } else if ("4".equals(assessObj)) {
                    //9通信室内设备   13 通信基站
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_9");
                    Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerr1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_13");
//                    Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerr2);
                    //线数据
                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line9");
                    Layerr layerrline1 = new Layerr(serverUrl, new ArrayList<>());
                    layerrs.add(layerrline1);
//                    serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line13");
//                    Layerr layerrline2 = new Layerr(serverUrl, new ArrayList<>());
//                    layerrs.add(layerrline2);
                }*/
                //点数据
                serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode());
                Layerr layerr1 = new Layerr(serverUrl, new ArrayList<>());
                layerrs.add(layerr1);
                //线数据
                serverUrl = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line");
                Layerr layerr2 = new Layerr(serverUrl, new ArrayList<>());
                layerrs.add(layerr2);
            }
        }
        serverUrl = iServerHttp + "/iserver/services/map-fxfzypg/rest/maps/district_boundary_china@fxfzypg";
        Layerr layerr = new Layerr(serverUrl, new ArrayList<>());
        layerrs.add(layerr);
        return layerrs;
    }

    private List<Layer> getLayers(LegendVO legendVo, Map<String, String> tempLayerUrlMap) {
        List<Layer> layers = new ArrayList<>();
        MapTemplate mapTemplate = legendVo.getMapTemplate();
        String serverUrl1 = mapTemplate.getServerUrl();
        String url_1 = mapTemplate.getServerIpPort() + serverUrl1;
        if (tempLayerUrlMap != null && !tempLayerUrlMap.isEmpty()) {
            //0评估/1区划/2生命线破坏等级分析图/3生命线功能失效分析图
            String dataType = legendVo.getDataType();
            if ("0".equals(dataType) || "1".equals(dataType)) {
                url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode());
                String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                Layer layer1 = new Layer("TILE", true, layerName, url_1);
                layers.add(layer1);
            } else if ("2".equals(dataType) || "3".equals(dataType)) {//生命线破坏等级分析图、功能失效分析图
                /*//0供水系统，1供气系统，2供电系统，3交通系统，4通信系统，
                String assessObj = legendVo.getAssessObj();
                //地震输入方式0为设定烈度,1为地震影响场
//                String seismicInputMode = legendVo.getSeismicInputMode();
                //确定评估：烈度时（ld1，ld2，ld3，ld4，ld5）
//                String condition = legendVo.getCondition();
                if ("0".equals(assessObj)) {
                    //1地下管网，2水厂水池，11 水厂泵房
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_1");
                    String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer1 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_2");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer2 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_11");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer3 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer3);
                    //线数据
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line1");
                    String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line2");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer2 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line11");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer3 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer3);
                } else if ("1".equals(assessObj)) {
                    //3燃气储气罐14 燃气门站15 供气
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_3");
                    String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer1 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_14");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer2 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_15");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer3 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer3);
                    //线数据
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line3");
                    String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line14");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer2 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line15");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer3 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer3);
                } else if ("2".equals(assessObj)) {
                    //6变电站 8电缆线路12 重要发电厂房
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_6");
                    String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer1 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_8");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer2 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_12");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer3 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer3);
                    //线数据
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line6");
                    String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line8");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer2 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer2);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line12");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer3 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer3);
                } else if ("3".equals(assessObj)) {
                    //4 桥梁 5道路
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_4");
                    String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer1 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_5");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer2 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer2);
                    //线数据
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line4");
                    String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line5");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer2 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer2);
                } else if ("4".equals(assessObj)) {
                    //9通信室内设备   13 通信基站
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_9");
                    String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer1 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_13");
                    layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer layer2 = new Layer("TILE", true, layerName, url_1);
                    layers.add(layer2);
                    //线数据
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line9");
                    String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer1);
                    url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line13");
                    linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                    Layer linelayer2 = new Layer("TILE", true, linelayerName, url_1);
                    layers.add(linelayer2);
                }*/
                //点数据
                url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode());
                String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                Layer layer1 = new Layer("TILE", true, layerName, url_1);
                layers.add(layer1);
                //线数据
                url_1 = tempLayerUrlMap.get(mapTemplate.getDictCode() + "_line");
                String linelayerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
                Layer linelayer1 = new Layer("TILE", true, linelayerName, url_1);
                layers.add(linelayer1);
            }
        }
        url_1 = iServerHttp + "/iserver/services/map-fxfzypg/rest/maps/district_boundary_china@fxfzypg";
        String layerName = url_1.substring(url_1.lastIndexOf("/") + 1).split("@")[0];
        Layer layer1 = new Layer("TILE", true, layerName, url_1);
        layers.add(layer1);
        return layers;
    }

    //获取临时图层url
    private String getSqlTempLayer(String layerUrl, String sqlText, boolean showLabelBool) {
        String resultUrl = layerUrl;
        if (PlatformObjectUtils.isNotEmpty(sqlText)) {
            JSONArray jsonArray = getLayersRJson(layerUrl);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONArray layers = jsonArray.getJSONObject(i).getJSONObject("subLayers").getJSONArray("layers");
                for (int j = 0; j < layers.size(); j++) {
                    JSONObject layer = layers.getJSONObject(j);
                    layer.put("displayFilter", sqlText);
                    if (showLabelBool == false && layer.getString("ugcLayerType") == "THEME") {
                        if (layer.getJSONObject("theme").getString("type") == "LABEL") {//文字标签子图层
                            layer.put("visible", showLabelBool);
                        }
                    }
                }
            }
            String jsonStr = JSON.toJSONString(jsonArray);
            JSONObject resultObj = postTempLayersSet(layerUrl, jsonStr);
            String newResourceID = resultObj.getString("newResourceID");
            String newResourceLocation = resultObj.getString("newResourceLocation");
            if (PlatformObjectUtils.isNotEmpty(newResourceLocation)) {
                resultUrl = newResourceLocation.replace(".rjson", "");
            }
        }
        System.out.println("resultUrl:{}"+resultUrl);
        return resultUrl;
    }

    private JSONArray getLayersRJson(String layerUrl) {
        try {
            String dataUrl = layerUrl + "/layers.rjson";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class);
            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(exchange));
            JSONArray body = JSON.parseArray(jsonObject.getString("body"));
            if (body == null) {
                return null;
            }
            return body;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private JSONObject postTempLayersSet(String layerUrl, String jsonStr) {
        JSONObject result = new JSONObject();
        String dataUrl = layerUrl + "/tempLayersSet.rjson";
        try {
            dataUrl = URLDecoder.decode(dataUrl, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
        dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "application/json; charset=UTF-8");

        HttpEntity<String> entity = new HttpEntity<>(jsonStr, headers);
        ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, String.class);
        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(exchange));
        JSONObject body = JSON.parseObject(jsonObject.getString("body"));
        if (body == null) {
            return null;
        }
        result = body;

        return result;
    }

    public RestResponse generateGraph(RequestVO requestVO, String taskId, MapTemplate mapTemplate) {
        String fileName = mapTemplate.getDictCode();
        RestResponse restResponse = null;
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("supergraphRestTemplateUrl") + "/webprinting/rest/webprinting/v1/jobs.json";
        JSONObject requestJsonVo = (JSONObject) JSONObject.toJSON(requestVO);
        String json = JSONObject.toJSONString(requestJsonVo);
        log.info(json);
        Map map = JSONObject.parseObject(json, Map.class);
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendPostHttpRequest(url, map);
        String body = stringResponseEntity.getBody();
        List<ResponseVO> responseVO = JSON.parseArray(body, ResponseVO.class);
        String path = "";
        if (responseVO != null && responseVO.size() > 0) {
            path = responseVO.get(0).getPath();
            //获取出图任务状态
            path = getMapLayerPrintJob(path);
            if (path.equals("出图失败")) {
                return RestResponse.fail("出图失败！");
            }
            path = responseVO.get(0).getPath() + "/" + "result";
            String savePath = ctLocalDir;
            path = path.replace("@", "%40");
            System.out.println("路径  " + path);
            restResponse = downloadsFile.downloadByUrl(path, savePath, taskId, fileName, mapTemplate.getFlag());
        }
        File file = new File(ctLocalDir);
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()) {
                file1.delete();
            }
        }

        return restResponse;
    }

    //获取出图任务状态
    private String getMapLayerPrintJob(String path) {
        String result = null;
        try {
            String dataUrl = path + ".json";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return "出图失败";
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            /*if (body == null) {
                return "出图失败";
            }*/
            if (body.getString("status").equals("ERROR")) {
                return "出图失败";
            }
            while (!body.getString("status").equals("ERROR") && !body.getString("status").equals("FINISHED")) {
                Thread.sleep(1000);
                //获取任务执行百分比
                result = getMapLayerPrintJob(path);
                if (result.equals("出图成功") || result.equals("出图失败")) {
                    break;
                }
            }
            if (body.getString("status").equals("FINISHED")) {
                return "出图成功";
            } else if (body.getString("status").equals("ERROR")) {
                return "出图失败";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = getMapLayerPrintJob(path);
        }
        return result;
    }
}
